ModuleLoader   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 24
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A loadModule 0 13 2
1
import {Observer} from '@enbock/state-value-observer/ValueObserver';
2
import React from 'react';
3
4
interface LoadedModuleDictionary {
5
  [name: string]: typeof React.Component,
6
}
7
8
export default class ModuleLoader {
9
  moduleState: Observer<typeof React.Component | null>;
10
  dictionary: LoadedModuleDictionary;
11
  pathToRoot: string;
12
13
  constructor(pathToRoot: string, moduleState: Observer<typeof React.Component | null>) {
14 2
    this.moduleState = moduleState;
15 2
    this.dictionary = {};
16 2
    this.pathToRoot = pathToRoot;
17
  }
18
19
  async loadModule(modulePath: string) {
20
    let module: typeof React.Component;
21
22 3
    if (!this.dictionary.hasOwnProperty(modulePath)) {
23 2
      const filePath = (this.pathToRoot + modulePath + '.js').replace('.././', '../');
24 2
      module = (await import(filePath)).default as typeof React.Component;
25 2
      this.dictionary[modulePath] = module;
26
    } else {
27 1
      module = this.dictionary[modulePath];
28
    }
29
30 3
    this.moduleState.value = module;
31
  }
32
}
33